package co.fitstart.entity.market;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.user.User;

/**
 * 用户打卡课程
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "market_course_round")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class MarketCourseRound {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 课程编号 */
    private String code;
    
    /** 打卡天数 总 */
    private int signinDays;
    
    /** 打卡分钟 总 */
    private long signinMinutes;
    
    /** 连续打卡天数 */
    private int insistDays;
    
    private Date createTime;
    
    private boolean joinGroup;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private MarketCourse course;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private User user;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public MarketCourseRound() {
        
    }
    
    /**
     * 
     * @param course
     * @param user
     */
    public MarketCourseRound(MarketCourse course, User user) {
        // TODO generate courseRound's code
        
        this.signinDays = 0;
        this.signinMinutes = 0;
        this.insistDays = 0;
        this.createTime = new Date();
        this.course = course;
        this.user = user;
        this.disabled = false;
        this.joinGroup = false;
    }
    
    /**
     * 
     * @return
     */
    public MarketCourseRound editInsistDays() {
        this.insistDays = this.insistDays + 1;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public MarketCourseRound resetInsistDays() {
        this.insistDays = 0;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public MarketCourseRound editSigninDays() {
        this.signinDays = this.signinDays + 1;
        return this;
    }
    
    /**
     * 
     * @param minutes
     * @return
     */
    public MarketCourseRound editSigninMinutes(long minutes) {
        this.signinMinutes = this.signinMinutes + minutes;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public MarketCourseRound joinGroup() {
        this.joinGroup = true;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the signinDays
     */
    public int getSigninDays() {
        return signinDays;
    }

    /**
     * @return the signinMinutes
     */
    public long getSigninMinutes() {
        return signinMinutes;
    }

    /**
     * @return the insistDays
     */
    public int getInsistDays() {
        return insistDays;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the joinGroup
     */
    public boolean isJoinGroup() {
        return joinGroup;
    }

    /**
     * @return the course
     */
    public MarketCourse getCourse() {
        return course;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param signinDays the signinDays to set
     */
    public void setSigninDays(int signinDays) {
        this.signinDays = signinDays;
    }

    /**
     * @param signinMinutes the signinMinutes to set
     */
    public void setSigninMinutes(long signinMinutes) {
        this.signinMinutes = signinMinutes;
    }

    /**
     * @param insistDays the insistDays to set
     */
    public void setInsistDays(int insistDays) {
        this.insistDays = insistDays;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param joinGroup the joinGroup to set
     */
    public void setJoinGroup(boolean joinGroup) {
        this.joinGroup = joinGroup;
    }

    /**
     * @param course the course to set
     */
    public void setCourse(MarketCourse course) {
        this.course = course;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}
